var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session=require('express-session');
var index = require('./routes/index');
var classify=require('./routes/classify');
var bookDetil=require('./routes/bookDetil');
var shopCar=require('./routes/shopCar');
var order=require('./routes/order');
var orderOk=require('./routes/orderOk');
var orderDo=require('./routes/orderDo');
var login = require('./routes/login');
var presnol = require('./routes/presnol');
var orderQueren=require('./routes/orderQueren');
var search=require('./routes/search');
var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use(session({
  secret: 'keyboard cat', //一个String类型的字符串，作为服务器端生成session的签名
  resave: true, //(是否允许)当客户端并行发送多个请求时，其中一个请求在另一个请求结束时对session进行修改覆盖并保存。
  saveUninitialized: true //初始化session时是否保存到存储
}))


app.use('/', index);
app.use('/classify',classify);
app.use('/bookDetil', bookDetil);
app.use('/shopCar', shopCar);
app.use('/order', order);
app.use('/orderOk', orderOk);
app.use('/orderDo', orderDo);
app.use('/login', login);
app.use('/presnol', presnol);
app.use('/orderQueren', orderQueren);
app.use('/search', search);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

// error handler
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render('error');
});

module.exports = app;
